<?php
class Album extends AlbumAppModel {
	var $useTable = 'sys_albums';
	var $validate = array (
			'title' => array (
					'rule' => 'notEmpty',
					'message' => '请输入相册名' 
			) 
	);
	
	/**
	 * 图片相册操作权限验证(相册图片删除)
	 * @author lj@gootop.net  
	 * @Date 2012-11-16
	 * @param
	 * @return
	 */
	function ChkAblumDel($CompUserId, $AlbumId) {
		$result = array ();
		// 获取相册信息
		$arrAblum = $this->find ( 'first', array (
				'conditions' => array (
						'Album.user_id' => $CompUserId,
						'Album.id' => $AlbumId 
				) 
		) );
		if ($arrAblum) {
			if ($arrAblum ['Album'] ['type_id'] == 0) { // 判断是否系统相册
				$flag = false;
				$message = '系统相册不能删除！';
			} else {
				//判断是否同一用户
				if ($arrAblum ['Album'] ['user_id'] == $CompUserId){
					// 判断是否存在图片
					ClassRegistry::init ( 'Album.AlbumPic' );
					$albumPic = new AlbumPic ();
					$albumPic->recursive = - 1;
					$albumPic_count = $albumPic->getPicsCountByAlbumId($CompUserId, $AlbumId);
				
					if ($albumPic_count > 0) {
						$flag = false;
						$message = '相册：' . $arrAblum ['Album'] ['title'] . '下存在图片，请先删除图片！';
					} else {
						$flag = true;
						$message = '操作成功！';
					}
				}else{
					$flag = false;
					$message = '无权操作！';
				}
			}
		} else {
			$flag = false;
			$message = '相册不存在！';
		}
		
		$result ['flag'] = $flag;
		$result ['message'] = $message;
		
		return $result;
	}
	/**
	 * 根据相册id获取相册信息
	 * @author lj@gootop.net  
	 * @Date 2012-11-16
	 * @param
	 * @return
	 */
	function getAlbumById($id) {
		$list = $this->find ( 'first', array (
				'conditions' => array (
						'Album.id' => $id 
				) 
		) );
		return $list;
	}
	/**
	 * 会员相册 option 列表
	 * @author zmx@gootop.net  
	 * @Date 2012-11-19
	 * @param
	 * @return 
	 */
	function getAlbumList($userId){
		return $this->find ( 'list', array (
			'conditions' => array('Album.user_id ' => $userId),
			'order' => 'Album.id ASC' 
		));
	}
}
?>